pp108 : Creating and Using Composite Classes

Creating and Using Composite Classes

This topic describes the procedure to create and use composite classes with the help of an example.


In complex applications, standard classes derived from single database tables may be deficient in providing support to all the functions within the application. In such situations, there is a need for classes that contain information from more than one database table.

These are called Composite classes, which are created by clubbing two or more objects together. A virtual reference is created between the primary object and the secondary object such that the request is framed reading data from both the objects. The structure of the composite class is created using the Object Layout provided by WS-AppServer. These classes are created in a nested structure.

Example


The following is an example of creating a composite class using theOrdersandOrderDetailstables from the SQL-Server Northwind's database. Using the Object Layout provided by WS-AppServer, a custom class called FullOrder is defined, which aggregates a Header element and Lines element. The Header element is represented by theOrdersobject, while the Lines element is represented by a collection ofOrderDetailsobjects (sequenced).
The format used to club one object with another is <Name of the Package in WS-AppServer>::<name of the standard class in that package>. In the Object Layout, the custom class would form the following structure:

<FullOrder>
    <OrderID unique="true">i4</OrderID>
    <Header occ="1">HB Northwind::Orders</Header>
    <Lines occ="*">HB Northwind::OrderDetails</Lines>
</FullOrder>

In the above code, the package is Northwind, and Orders and OrderDetails are the standard classes. Based on this layout, the composite class would be framed as follows.

<FullOrder>
    <OrderID>11049</OrderID>
    <Header>
        <OrderID>11049</OrderID>
        <CustomerID>XYZ</CustomerID>
        <EmployeeID>3</EmployeeID>
        <OrderDate>1998-04-24T00:00:00.0</OrderDate>
        <RequiredDate>1998-05-22T00:00:00.0</RequiredDate>
        <ShippedDate>1998-05-04T00:00:00.0</ShippedDate>
        <ShipVia>1</ShipVia>
        <Freight>8.34</Freight>
        <ShipName>XYZ Shipment</ShipName>
        <ShipAddress>Av. Brasil, 442</ShipAddress>
        <ShipCity>Campinas</ShipCity>
        <ShipRegion>SP</ShipRegion>
        <ShipPostalCode>04876-786</ShipPostalCode>
        <ShipCountry>Brazil</ShipCountry>
    </Header>
    <Lines seqId="1">
        <OrderID>11049</OrderID>
        <ProductID>12</ProductID>
        <UnitPrice>38</UnitPrice>
        <Quantity>4</Quantity>
        <Discount>0.2</Discount>
    </Lines>
    <Lines seqId="2">
        <OrderID>11049</OrderID>
        <ProductID>2</ProductID>
        <UnitPrice>19</UnitPrice>
        <Quantity>10</Quantity>
        <Discount>0.2</Discount>
    </Lines>
</FullOrder>


Note: Before the composite class is used in a SOAP request, it has to be compiled. The compilation will be successful only if the Java code of both the objects is available.

Related concepts

BusObjects

Related tasks

Implementing Custom Logic with Extension Classes

Related information

Extending the Business Logic Using Custom Classes
Managing Transactions Using WS-AppServer